#!/usr/bin/ruby

require 'test/unit'
require 'lib/rire'
require 'parsedate'

class TestRss < Test::Unit::TestCase
  def setup
    @dsl = Rire::DSL.new($rire_home + '/plugin')
    @dsl.instance_eval <<-EOD
      def execute(src)
        instance_eval(src, 'unit.dsl', 1)
      end
    EOD
  end

  def test_read_file
    src = <<-"SCENARIO"
      define_task do
        subscribe.rss :config => {
          :link => "#{$rire_home}/test/subscribe/config_rss20.xml"
		}
      end
    SCENARIO

    ctx = @dsl.execute(src)

    assert_equal('item title 1', ctx.entries[0].title)
    assert_equal('item title 2', ctx.entries[1].title)
    assert_equal('item title 3', ctx.entries[2].title)
    assert_equal('item title 4', ctx.entries[3].title)
    assert_equal('item title 5', ctx.entries[4].title)

    assert_equal('http://www.example.com/gtaka555/20080120/p1', ctx.entries[0].link)
    assert_equal('http://www.example.com/gtaka555/20080117/p1', ctx.entries[1].link)
    assert_equal('http://www.example.com/gtaka555/20080116/p1', ctx.entries[2].link)
    assert_equal('http://www.example.com/gtaka555/20080115/p1', ctx.entries[3].link)
    assert_equal('http://www.example.com/gtaka555/20080115/p2', ctx.entries[4].link)

    assert_instance_of(Time, ctx.entries[0].date)
  end

  def teardown
  end
end

